<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__STATIC__/layout/css/font-awesome.css?v=4.4.0" rel="stylesheet">
     <link href="__STATIC__/layout/css/plugins/summernote/summernote.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
     <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/plugins/webuploader/webuploader.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/demo/webuploader-demo.css">
    <!-- jqgrid-->
    <link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    
    <style>
        .radio-inline input[type=radio] {
            margin-top: 4px
        }
    </style>
</head>

<body style="color:#333;padding:3px;" class="x_sorll">
    <!-- 标题 -->
    <div class="page-heade">
        <h2 class="title_color text-center">AP费用申请 </h2>
    </div>
    <!-- 标题 -->
    <form class="form-inline" id="zhuapply">
    	<input type="hidden" name="aid" id="aid" value="{$aid}"/>
        <table class="table-bordered table text-left" border="1">
            <tr>
                <td><label for="" class="form-label">主题<span class="colorRed">*</span>：</label></td>
                <td><input type="text" class="form-control" id="title" name="title"{if condition="$aid neq 0"} value="{$apply.title}" readonly {/if}></td>
            </tr>
            <tr>
                <td><label for="" class="form-label">渠道类型<span class="colorRed">*</span>：</label></td>
                <td><select name="channel" id="channel" class="form-control select"  {if condition="$aid neq 0"}disabled{/if}>
                	<option value="0">请选择</option>
                    {if condition="$aid neq 0"}
                        {volist name="channel" id="vo"}
                            {if condition="$apply.channel_id eq $vo.id"}
                            <option value="{$vo.id}" selected>{$vo.title}</option>
                            {else/}
                            <option value="{$vo.id}">{$vo.title}</option>
                            {/if}
                        {/volist}
                    {else/}
                	{volist name="channel" id="vo"}
						<option value="{$vo.id}">{$vo.title}</option>
                	{/volist}
                    {/if}
                    
            </select></td>
            </tr>
            <tr>
                <td><label for="" class="form-label">销售区域<span class="colorRed">*</span>：</label></td>
                <td>
                    <label class="radio-inline">
				  <input type="radio" checked name="area" id="inlineRadio1" value="1">分区
				</label>
                    <label class="radio-inline">
				  <input type="radio" name="area" id="inlineRadio2" value="2">省份
				</label>
                    <label class="radio-inline">
				  <input type="radio" name="area" id="inlineRadio3" value="3">城市
				</label>
                    <label class="radio-inline">
				  <input type="radio" name="area" id="inlineRadio4" value="4">经销商
				</label>
                    <label class="radio-inline">
				  <input type="radio" name="area" id="inlineRadio5" value="5">系统
				</label>
                    <label class="radio-inline">
				  <input type="radio" name="area" id="inlineRadio6" value="6">网点
				</label>
                </td>
            </tr>
            <tr>
                <td><label for="" class="form-label">产品维度<span class="colorRed">*</span>：</label></td>
                <td>
                    <label class="radio-inline">
				  <input type="radio" name="pro" checked id="inlineRadio11" value="1">品牌
				</label>
                    <label class="radio-inline">
				  <input type="radio" name="pro" id="inlineRadio22" value="2">品类
				</label>
                    <label class="radio-inline">
				  <input type="radio" name="pro" id="inlineRadio3" value="3">系列
				</label>
                </td>
            </tr>
            {if condition="$aid neq 0"}
                {if $apply.state==2}
             <tr>
                <td><label for="" class="form-label">作废原因<span class="colorRed">(温馨提示：如作废申请，则必须填写)</span>：</label></td>
                <td>
                    <textarea name="feireason" class="form-control" style="width: 70%;resize: none;"></textarea>
                </td>
            </tr>
            {/if}{/if}
        </table>
        <div class="row border-bottom link-block" style="margin-left: 0;margin-right: 0">
            <button class="btn btn-success btn-sm" type="button" id="add">添加数据</button>
            <button class="btn btn-success btn-sm" type="button">导入数据</button>
            <div class="form-group">
                (至少包含一条AP费用明细)<span class="colorRed">温馨提示：1）一个活动不要分开申请，否则会影响该活动的ROI;2)多个活动不要放到同一个申请中申请，否则会影响后续的反馈、核销。谢谢合作</span>
            </div>
        </div>

   
    <div class="no-padding">
        <table class="table row-margin-top table-bordered text-center bud_hei">
            <tr class="info">
                <td style="min-width: 240px;width: 240px" colspan="2" rowspan="2">
                      <input type="button" class="btn btn-info btn-sm qx" value="全选"/>
               <input type="button" class="btn btn-info btn-sm fx" value="反选"/>
               <input type="button" class="btn btn-info btn-sm plsc" value="批量删除"/>
                </td>
                <td rowspan="2">No.</td>
                <td rowspan="2">明细编号</td>
                <td colspan="2">供货商信息</td>
                <td colspan="11">活动信息</td>
                <td colspan="8">费用详情</td>
                <td colspan="6">销量详情</td>
                <td rowspan="2">项目描述</td>
                <td rowspan="2">备注</td>
            </tr>
            <tr class="info">
                <td>供应商编码</td>
                <td>供应商名称</td>
                <td>分区</td>
                <td>省份</td>
                <td>城市</td>
                <td>经销商</td>
                <td>系統</td>
                <td>网点</td>
                <td>品牌</td>
                <td>品类</td>
                <td>系列</td>
                <td>活动开始时间</td>
                <td>活动结束时间</td>
                <td>二级费用科目</td>
                <td>三级费用科目</td>
                <td>未税费用金额(元)</td>
                <td>税率</td>
                <td>是否增值税可抵扣</td>
                <td>含税费用金额(元)</td>
                <td>实际投入费用(元)</td>
                <td>费用支付方式</td>
                <td>预计销量(元)</td>
                <td>预计费用率</td>
                <td>2SR基准销量(元)</td>
                <td>基准销量(元)</td>
                <td>新增销量(元)</td>
                <td>预计ROI</td>
            </tr>
            {if condition="$aid neq 0"}
				{volist name="apply_de" id="de"}
					<tr class="text-center">
						 <td><input type="checkbox" value="{$de.id}" class="ckde"/> </td>
                         <td>
                            <input type="button" class="btn btn-info btn-sm" value="修改" onclick="xiugai({$de.id})"/>
                            <input type="button" class="btn btn-danger btn-sm" value="删除本条" onclick="shanchu({$de.id})"/>
                         </td>
                         <td>{$i}{if condition="$de.is_bu eq 1"}<span style="color:red;border:1px solid red;">补单</span>{/if}</td>
                         <td>{$apply.no}_{$de.detail_no}<a href="{:url('mingxijuece')}?did={$de.id}" title="决策依据" class="J_menuItem" ><span style="display: none;">决策依据</span><span class="glyphicon glyphicon-zoom-in fangda" aria-hidden="true" style="display: inline-block;"></span></a></td>
                         <td>{$de.gys_no}</td><td>{$de.gys_name}</td><td>{$de.fenqu}</td><td>{$de.sheng}</td><td>{$de.shi}</td>
                         <td>{$de.jxs}</td><td>{$de.system}</td><td>{$de.net}</td><td>{$de.brand}</td><td>{$de.category}</td><td>{$de.series}</td>
                         <td>{$de.start_time}</td>
                         <td>{$de.end_time}</td><td>{$de.kemu2}</td><td>{$de.kemu3}</td><td class="num2">{$de.zonge}</td><td><span class="num2">{$de.shuilv}</span>%</td>
                         {if condition="$de.dikou eq 1"}<td>是</td>{else/}<td>否</td>{/if}<td class="num2">{$de.hanshui}</td><td class="num2">{$de.hanshui}</td>
                         <td>{$de.zffs}</td><td class="num2">{$de.zong_xiaoliang}</td><td><span class="num2">{$de.yujifeiyonglv}</span>%</td><td>0.00</td><td class="num2">{$de.jizhun_xiaoliang}</td>
                         <td class="num2">{$de.xinxiaoliang}</td><td><span class="num2">{$de.yujiroi}</span>%</td><td><a onclick="tanchuan({$de.id})">点击查看</a></td><td>{$de.remark}</td>
					</tr>
				{/volist}
            {/if}
            <tr>
                <td style="min-width: 240px;width: 240px" colspan="2">
                       <input type="button" class="btn btn-info btn-sm qx" value="全选"/>
               <input type="button" class="btn btn-info btn-sm fx" value="反选"/>
               <input type="button" class="btn btn-info btn-sm plsc" value="批量删除"/>
                </td>
                <td colspan="8" class="text-right">合计</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td class="text-right num2">{$all.zonges}</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td class="text-right num2">{$all.hanshuis}</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td class="text-right num2">{$all.zong_xiaoliangs}</td>
                <td><span class="num2">{$all.yujifeiyonglvs}</span>%</td>
                <td class="text-right">0.00</td>
                <td>&nbsp;</td>
                <td class="text-right num2">{$all.news}</td>
                <td title="所有明细毛利求和/费用"><span class="num2">{$all.yujirois}</span>%</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
        </table>
        <div class="form-group white-bg" style="margin:20px 10px 20px 20px;">
            <div id="uploader" class="wu-example">
                <!--用来存放文件信息-->
                <div id="thelist" class="uploader-list">
                   {volist name="fujian" id="fo"}
                        <h4>{$fo.file_name}</h4>
                   {/volist}
                </div>
                <div class="btns">
                    <div id="picker">选择文件</div>
                    <button id="ctlBtn" class="btn btn-default">开始上传</button>
                </div>
                <input type="hidden" name="attach" id="attach" {if condition="$aid neq 0"} value="{$apply.annex_id}" {/if} >
            </div>
            <span>注：最多上传15个文件，每个文件小于50M,支持格式：</span><br>jpg,bnp,gif,png,jpeg,tif,raw,doc,docx,xls,xlsx,ppt,pptx,txt,pdf,rar,zip,mp4,avi,rmvb,rm,mid,3gp,AVI,3GP,,mpg,mp3,wma,wav
        </div>
         {if condition="$aid neq 0"}
          {if $apply.state==2}
         <table class="table table-bordered text-left bud_hei">
            <tr class="info">
                <th class="text-left font-bold">审批意见</th>
            </tr>
            {volist name="logs" id="l"}
          <tr>
              <td>{$l.USERNAME} 审批动作：{$l.MEMO}；审批意见：{if $l.COMMENTS}{$l.COMMENTS}{else/}无{/if}(审批时间：{$l.ACTIONTIME})</td>
          </tr>
          
          {/volist}
      </table>
      {/if}{/if}
        <div class="row text-center no-padding">
             {if condition="$aid eq 0"}
                <input type="button" class="btn btn-primary" onclick="tijiao(1)" value="保存为草稿"/>
                <input type="button" class="btn btn-warning" onclick="tijiao(3)" value="保存并提交流程"/>
            {else/}
                {if $apply.state==2}
                 <input type="hidden" id="nodeKey" name="nodeKey"/>
                  <input type="hidden" id="selectId" name="selectId"/>
                  <input type="hidden" id="selectName" name="selectName"/>
                    {volist name="btn.nextNodes" id="b"}
                      {if $b.nodeName=='结束'}
                      <input type="button" class="btn-danger btn" onclick="zuofei('{$b.nodeKey}','{$b.selectId}','{$b.selectName}')" value="点此作废"/>
                      {else/}
                      <input type="button" class="btn-info btn" onclick="baocun('{$b.nodeKey}','{$b.selectId}','{$b.selectName}')" value="保存并提交工作流"/>
                      {/if}
                    {/volist}
                {else/}
            <input type="button" class="btn btn-primary" onclick="tijiao(1)" value="保存为草稿"/>
            <input type="button" class="btn btn-warning" onclick="tijiao(3)" value="保存并提交流程"/>
            
            {/if}{/if}
            <button  class="btn btn-info" type="button" onclick="back()">返回</button>
        </div>
        </form>
    </div>
   <!-- 全局js -->
    <script src="__STATIC__/layout/js/jquery.min.js?v=2.1.4"></script>
    <script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
    <script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
    <script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
    <script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="__STATIC__/layout/js/plugins/summernote/summernote.min.js"></script>
<script src="__STATIC__/layout/js/plugins/summernote/summernote-zh-CN.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>

   <script src="__STATIC__/layout/js/contabs_sub.js"></script>
    <script>
        var fr={$from};
        function baocun(nodeKey,selectId,selectName){
  $("#nodeKey").val(nodeKey)
  $("#selectId").val(selectId)
  $("#selectName").val(selectName)
   $.ajax({
          cache: true,
          type: "POST",
          url:"{:url('baocunchuli')}",
          data:$('#zhuapply').serialize(),// 你的formid
          async: false,
          error: function(request) {
            alert("Connection error");
          },
          success: function(data) {
            //alert(data);
            //var res=JSON.parse(data);
                    var res1=JSON.parse(data);
                            if(res1["state"]==1){
                              swal({
                                title: "完成",
                                text: "操作已成功",
                                type: "success"
                                },function(){
                                  if(fr==1)
                                        location.href="{:url('index')}"
                                  else
                                        location.href="{:url('Workflowdb/index')}"
                                });

                          }else{
                            swal({
                            title: "错误",
                            text:  res1["msg"],
                            type: "warning"
                            });
                          }           
          }
        });
}
        function zuofei(nodeKey,selectId,selectName){
  $("#nodeKey").val(nodeKey)
  $("#selectId").val(selectId)
  $("#selectName").val(selectName)
   $.ajax({
          cache: true,
          type: "POST",
          url:"{:url('zuofeichuli')}",
          data:$('#zhuapply').serialize(),// 你的formid
          async: false,
          error: function(request) {
            alert("Connection error");
          },
          success: function(data) {
           // alert(data);
            //var res=JSON.parse(data);
                    var res1=JSON.parse(data);
                            if(res1["state"]==1){
                              swal({
                                title: "完成",
                                text: "操作已成功",
                                type: "success"
                                },function(){
                                   if(fr==1)
                                        location.href="{:url('index')}"
                                    else
                                        location.href="{:url('Workflowdb/index')}"
                                  //parent.layer.close(parent.layer.getFrameIndex(window.name))
                                  //
                                });

                          }else{
                            swal({
                            title: "错误",
                            text:  res1["msg"],
                            type: "warning"
                            });
                          }         
          }
        });
}
    </script>
    <script>
    //修改
    function xiugai(did){
	    var index = layer.open({
	                            type:2,
	                            title:'修改数据',
	                            area:['100%','100%'],
	                            maxmin:true,
	                            content:'{:url("xiugai")}?did='+did
	                        })
	}
    //提交
     function tijiao(state){
         var num=0;
         var aid={$aid};
         
        $(".ckde").each(function(){
            num++;
        })
        var msg="";
        if($("#title").val()==""){
            msg="主题不能为空";
        }else if(aid==0){
            msg="这不是一张有效的单据";
        }
        else if(num==0){
            msg="至少一条明细";
        }
        if(msg==""){
            
            $.post("{:url('baocunapply')}",{aid:aid,fujian:$("#attach").val(),state:state,title:$("#title").val()},function(re){
                //alert(re);
                 var res=JSON.parse(re);
                                    if(res["state"]==1){
                                        swal({
                                        title: "完成",
                                        text: "操作已成功",
                                        type: "success"
                                        },function(){
                                           location.href="{:url('index')}";
                                        });
                                    }else{
                                          swal({
                                             title: "错误",
                                             text: res["msg"],
                                             type: "warning"
                                         });
                                    }
            })
        }else{
            swal({
                    title: "错误",
                    text:  msg,
                    type: "warning"
                    });
        }
    }
    //批量删除
    $(".plsc").click(function(){
	    var flag=0;
	    var num=0;
	    var dids=[];
	     $(".ckde").each(function(){
	        if($(this).prop("checked")){
	             dids[flag]=$(this).val();
	            flag++;

	        }
	        num++;
	    })
	     if(flag==num){
	        swal({
	                    title: "错误",
	                    text:  "至少保留一条明细",
	                    type: "warning"
	                    });
	     }else if(flag==0){
	        swal({
	                    title: "错误",
	                    text:  "您没有选择要删除的明细",
	                    type: "warning"
	                    });
	     }else{
	        var str=dids.join(',');
	        $.post("{:url('shanchu')}",{did:str,aid:$("#aid").val()},function(re){
	           if(re==1){
	                  swal({
	                    title: "成功",
	                    text:  "操作已完成",
	                    type: "success"
	                    },function(){
	                        location.href="{:url('addform')}?aid="+$("#aid").val();
	                    });
	           }else{
	               swal({
	                    title: "错误",
	                    text:  "您没有选择要删除的明细",
	                    type: "warning"
	                    });
	           }
	        })
	     }

	})
    //删除本条
    function shanchu(did){
	    var num=0;
	     $(".ckde").each(function(){
	        num++;
	    })
	     if(num>1){
	          $.post("{:url('shanchu')}",{did:did,aid:$("#aid").val()},function(re){
	           if(re==1){
	                  swal({
	                    title: "成功",
	                    text:  "操作已完成",
	                    type: "success"
	                    },function(){
	                        location.href="{:url('addform')}?aid="+$("#aid").val();
	                    });
	           }else{
	               swal({
	                    title: "错误",
	                    text:  "您没有选择要删除的明细",
	                    type: "warning"
	                    });
	           }
	        })
	     }else{
	         swal({
	                    title: "错误",
	                    text:  "至少保留一条明细",
	                    type: "warning"
	                    });
	     }
	}
    $(".fx").click(function(){
	    $(".ckde").each(function(){
	        if($(this).prop("checked")){
	            $(this).prop("checked",false);
	        }else{
	            $(this).prop("checked",true);
	        }
	    })
	})
 $(".qx").click(function(){
       
        $(".ckde").prop("checked",true);
        
    })
    function tanchuan(did){
        $.post("{:url('getdes')}",{did:did},function(re){

            var data=JSON.parse(re);
            if(data["state"]==1){
                 parent.layer.open({
                type: 1,
                skin: 'layui-layer-demo', //样式类名
                closeBtn: false, //不显示关闭按钮
                shift: 2,
                shadeClose: true, //开启遮罩关闭
                content: data["msg"]
                });
            }else{
                   parent.layer.open({
                type: 1,
                skin: 'layui-layer-demo', //样式类名
                closeBtn: false, //不显示关闭按钮
                shift: 2,
                shadeClose: true, //开启遮罩关闭
                content: '系统繁忙请稍后再试'
                });
            }
        })
    		
    }
      $(".num2").each(function(){
        if(!isNaN(parseFloat($(this).html())))
         var num=parseFloat($(this).html()).toFixed(2);
        else
            var num="0.00";
        $(this).html(num);
    })
    $("#add").click(function(){
    	if($("input[name='title']").val()==""){
    		 swal({
                    title: "",
                    text:  "主题不能为空！",
                    type: "warning"
                    });
    	}else if($("#channel").val()==0){
    		 swal({
                    title: "",
                    text:  "请选择渠道类型！",
                    type: "warning"
                    });
    	}else{
    		 var index = layer.open({
		                    type:2,
		                    title:'添加数据',
		                    area:['80%','80%'],
		                    maxmin:true,
		                    content:'{:url("addData")}?area='+$("input[name='area']:checked").val()+'&pro='+$("input[name='pro']:checked").val()+'&channel='+$("#channel").val()+"&aid="+$("#aid").val()
		                })
		                layer.full(index)
    	}
    })
        function back(){
             if(fr==1)
                                        location.href="{:url('index')}"
                                    else
                                        location.href="{:url('Workflowdb/index')}"
        }
    </script>
    <!-- Web Uploader -->
<script type="text/javascript">
    // 添加全局站点信息
    var BASE_URL = '__STATIC__/layout/js/plugins/webuploader';
</script>
<script src="__STATIC__/layout/js/plugins/webuploader/webuploader.min.js"></script>
<script type="text/javascript">
	 // 文件上传
    jQuery(function() {
        var $ = jQuery,
            $list = $('#thelist'),
            $btn = $('#ctlBtn'),
            state = 'pending',
            uploader;

        var ids = [{if $aid!=0&&$apply.annex_id} value="{$apply.annex_id}" {/if}];
        uploader = WebUploader.create({

            // 不压缩image
            resize: false,

            // swf文件路径
            swf: BASE_URL + '/js/Uploader.swf',

            // 文件接收服务端。
            server: '{:url("upload/fileupload")}',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#picker'
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            $list.append( '<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">等待上传...</p>' +
                '</div>' );
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<div class="progress progress-striped active">' +
                    '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                    '</div>' +
                    '</div>').appendTo( $li ).find('.progress-bar');
            }

            $li.find('p.state').text('上传中');

            $percent.css( 'width', percentage * 100 + '%' );
        });

        uploader.on( 'uploadSuccess', function( file,response) {
            if(response.success)
                ids.push(response.id)
            $( '#'+file.id ).find('p.state').text(response.msg);
        });

        uploader.on( 'uploadError', function( file ) {
            $( '#'+file.id ).find('p.state').text('上传出错');
        });

        uploader.on( 'uploadComplete', function( file ) {
            $('#attach').val(ids.join(','))
            $( '#'+file.id ).find('.progress').fadeOut();
        });

        uploader.on( 'all', function( type ) {
            if ( type === 'startUpload' ) {
                state = 'uploading';
            } else if ( type === 'stopUpload' ) {
                state = 'paused';
            } else if ( type === 'uploadFinished' ) {
                state = 'done';
            }

            if ( state === 'uploading' ) {
                $btn.text('暂停上传');
            } else {
                $btn.text('开始上传');
            }
        });

        $btn.on( 'click', function() {
            if ( state === 'uploading' ) {
                uploader.stop();
            } else {
                uploader.upload();
            }
            return false
        });
     })

</script>
</body>

</html>